<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title>收款银行</title>
<link href="/dist/css/all_min.css" tppabs="http://www.115yz.com/xjkc/dist/css/all_min.css" rel="stylesheet">
</head>
<body>
<!--页头 start-->
<div id="header" class="kc-fixed kc-boxBody kc-commonHeight kc-commonbg">
    <div class="kc-rel">   
        <div class="float-left kc-cannel kc-pos">
             <div class="icon-bar" onclick="backUrl()"></div>
        </div>
        <a class="float-left kc-title textCenter">收款银行</a>
         <!-- <img src="/dist/img/msg.png" class="kc-msg"> -->
    </div>
</div>
<!--页头 end-->
<!--主体 start-->
<div id="bodyer" class="kc-padbody kc-boxBody bank-body ">
  <form id='form' >
    <div class="bank-block">
          <div><span>真实姓名 </span><input type="text" name="user_name" value="<?php echo $user['TrueName'] ?>"  required="required" readonly></div>
          <div><span>身份证号 </span><input type="text" name="ID" value="<?php echo $user['IDCard'] ?>" required="required" red></div>  
    </div>
    <div class="bank-block">
          <div><span>银行卡号 </span><input type="text" name="bank_numer" placeholder="请输入储蓄卡银行卡号" required="required"></div>
          <div><span>开户银行 </span>
          	<select name="bank_name" id="select">
                  <option value="">请选择银行卡</option>
                 <?php  foreach($bankSet as $v){  ?> 
                        <option value="<?php echo $v ?>"><?php echo $v ?></option>
                  <?php  } ?>    
          </select></div>  
    </div>
    <div class="bank-block bb1">
          <div><span>预留手机</span><input type="text" name="mobile" placeholder="请填写银行卡预留手机号" required="required"></div>
          <div><span>验证码</span><input type="text" name="verify" placeholder="请填写短信验证码" class="verify" required="required"><span id="v" style="font-weight: 200;font-size: 0.08rem;"  onclick="verifys()">获取验证码</span></div>  
    </div>
    <div class="bank-block">
          <div id="bank-block-last" style="margin-top: 8%;"><img src="/dist/img/point.png" class="circle" onclick="changeImg(this)"><span>我已阅读并同意<a href="#">《现金滴滴服务协议》</a></span></div>
          <div class="comfirm"><img src="/dist/img/comfirm.png"></div>
          <div class="shield2"><img src="/dist/img/shield2.png"><span>您的信息将进行加密保护</span></div>  
    </div>
  </form>
</div>
<script src="/resourse/jquery/jquery-1.11.3.min.js" tppabs="http://www.115yz.com/xjkc/resourse/jquery/jquery-1.11.3.min.js"></script>
<script src="/dist/js/all_min.js" tppabs="http://www.115yz.com/xjkc/dist/js/all_min.js"></script>
<script src="/dist/js/july.js" tppabs="http://www.115yz.com/xjkc/dist/js/all_min.js"></script>
<script type="text/javascript">
$('.comfirm').click(function(){
      let name = $('input[name="user_name"]').val();
      let result_isRealName = isEmpty(name,'真实姓名');
      if( result_isRealName==false) {return false};

	let ID = $('input[name="ID"]').val();
      let result_isCardNo = isCardNo(ID);
      if( result_isCardNo==false) {return false};

      let bankNumber = $('input[name="bank_numer"]').val();
      let result_is = isEmpty(bankNumber,"银行卡号");
      if( result_is==false) {return false};

      let bankNumbers = $('#select').val();
      if(bankNumbers==''){
      	openTip('请选择开户银行')
      	return false;
      }


      let phone = $('input[name="mobile"]').val();
      let result_p = isPhoneNumber(phone);
      if( result_p==false) {return false};
      
      let verify = $('input[name="verify"]').val();
      let result_v = isEmpty(verify,"验证码");
      if( result_v==false) {return false};

      let proto =isReadProtocol();
      if( proto==false) {return false};
      
        $.ajax({
          url:'/api.php/bank/bank2',
          type:'POST',
          data:$('#form').serialize(),
          success:function(data){
            var data =JSON.parse(data);
            console.log(data)
            if(data.status==1){
                  openTip('绑卡成功');
                  url('/index.php/index/authen');
            }else{
                  openTip(data.data.AppRetMsg); 
                  return false;
            }
          }
        })
})

function changeImg(img){
      let hostname = 'http://'+location.host;
   if(img.src ==hostname+'/dist/img/point.png'){
      img.src ="/dist/img/checked.png"    
   }else{
      img.src ="/dist/img/point.png"    
   }
}

//验证为空
// function isEmpty(item,e){
//       if(item.length==0){
//             openTip(e+'不能为空');
//             return false;
//       }
// }
//验证身份证号
function isCardNo(card){ 
	  let reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/; 
	  if(reg.test(card) === false){ 
            openTip("身份证输入不合法"); 
	      return false; 
	  } 
}
//验证手机号
// function isPhoneNumber(phone){
//       let myreg=/^[1][3,4,5,7,8][0-9]{9}$/;
//             if (!myreg.test(phone)) {
//                   openTip("预留手机号不合法"); 
//                 return false;
//             } 
// }
//验证真实姓名 少数名族的名字验证不过 故废除
function isRealName(name){
      let regName =/^[\u4e00-\u9fa5]{2,4}$/; 
      if(!regName.test(name)){ 
            openTip('真实姓名填写有误'); 
            return false; 
      }
}
//是否同意《现金滴滴服务协议》
function isReadProtocol(){
      let proto = $('.circle').attr('src')
      if(proto!=='/dist/img/checked.png'){
            openTip('请同意《现金滴滴服务协议》'); 
            return false;     
      }
}


//鉴卡验证码
function verifys(){

  let name = $('input[name="user_name"]').val();
  let result_isRealName = isEmpty(name,'真实姓名');
  if( result_isRealName==false) {return false};

  let ID = $('input[name="ID"]').val();
  let result_isCardNo = isCardNo(ID);
  if( result_isCardNo==false) {return false};

  let bankNumber = $('input[name="bank_numer"]').val();
  let result_is = isEmpty(bankNumber,"银行卡号");
  if( result_is==false) {return false};

      let bankNumbers = $('#select').val();
      if(bankNumbers==''){
      	openTip('请选择开户银行')
      	return false;
      }


	let phone = $('input[name="mobile"]').val();
	let result_p = isPhoneNumber(phone);
	if( result_p==false) {return false};

  $.ajax({
    url:'/api.php/bank/bank1',
    type:'POST',
    data:$('#form').serialize(),
    success:function(data){
      var data =JSON.parse(data);
      if(data.status==1){
        html='<input type="hidden" name="TrxId" value="'+data.data.TrxId+'">';
        $("#form").append(html);
        times();
        $("#v").removeAttr("onclick");
      }else{
            openTip(data.data.AppRetMsg); 
            // html='<input type="hidden" name="TrxId" value="'+data.data.TrxId+'">';
            // $("#form").append(html);
            return false;
      }
    }
  })
}

//倒计时
function times() {
      var setTime;
      var time = 60;
      setTime = setInterval(function () {
            if (time <= 0) {
                  clearInterval(setTime);
                  //添加事件
                  $("#v").attr("onclick", "verifys()");
                  //归还文本 
					$("#v").text('获取验证码');
                  return;
            }
            time--;
      msgs = time + "s后重发";
      $("#v").text(msgs);
      }, 1000);
}
</script>
</body>
</html>